﻿using Oracle.DataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using th.co.homepro;
using System.Configuration;

namespace DataAccess.ProxyConnections
{
    public class DatabaseProxy
    {
        private  OracleConnection _connection;

        public String GetOdacAuthConnectionString()
        {
            return
                String.Format(
                    @"User Id={0};Password={1};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={2})(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={3})));"
                    ,(string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_USER"]
                    ,(string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_PASS"]
                    ,(string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_HOST"]
                    ,(string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_SERVICE"]);

        }

        public  OracleConnection GetAuthConnection()
        {
            //Todo read from web config or textfile
            try
            {
                _connection = new OracleConnection();
                /**/
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Data Source={0};user id={1};password={2};"
                    , (string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_URL"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_USER"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_PASS"]);
                 
                _connection.ConnectionString = sb.ToString();
                //Auto_commit=false;
                return _connection;
            }
            catch (Exception e)
            {
                //new FileHandle().insertErrorLogFile(e.ToString(), "getAuthConnection");
                throw new Exception();
            }
        }

        public  OracleConnection GetBackoffcConnection()
        {
            try
            {
                _connection = new OracleConnection();
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Data Source={0};user id={1};password={2};"
                    , (string)ConfigurationManager.AppSettings["ORACLE_BACKOFFC_DB_URL"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_BACKOFFC_DB_USER"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_BACKOFFC_DB_PASS"]);
                _connection.ConnectionString = sb.ToString();
                //Auto_commit=false;
                return _connection;
            }
            catch (Exception e)
            {
                //new FileHandle().insertErrorLogFile(e.ToString(), "getBackoffcConnection");
                throw new Exception();
            }
        }

        public OracleConnection GetVrmConnection()
        {
            try
            {
                _connection = new OracleConnection();
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Data Source={0};user id={1};password={2};"
                    , (string)ConfigurationManager.AppSettings["ORACLE_VRM_DB_URL"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_VRM_DB_USER"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_VRM_DB_PASS"]);
                _connection.ConnectionString = sb.ToString();
                //Auto_commit=false;
                return _connection;
            }
            catch (Exception e)
            {
                //new FileHandle().insertErrorLogFile(e.ToString(), "getVrmConnection");
                throw new Exception();
            }
        }
    }
}
